package com.millstein.tsinglog.controller;

import com.millstein.tsinglog.annotation.ResponseResult;
import com.millstein.tsinglog.service.StatisticsService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/home")
@ResponseResult
@CrossOrigin
public class HomeController {

    @Autowired
    private StatisticsService statisticsService;

    /**
     * 根据类型查询统计数据
     * @param type 类型，1查本日的统计，2查本月的统计，3查所有的统计
     * @return
     */
    @GetMapping("/showDataByType")
    @RequiresPermissions("home:view")
    public Map<String, Object> showDataByType(Integer type) {
        return statisticsService.showDataByType(type);
    }

    /**
     * 获取首页上`根据分类对文章进行统计`的数据
     * @return
     */
    @GetMapping("/showArticleCountSortedByCategory")
    @RequiresPermissions("home:view")
    public List<Map<String, Object>> showArticleCountSortedByCategory() {
        return statisticsService.showArticleCountSortedByCategory();
    }

    /**
     * 获取首页上`根据标签对文章进行统计`的数据
     * @return
     */
    @GetMapping("/showArticleCountSortedByTag")
    @RequiresPermissions("home:view")
    public List<Map<String, Object>> showArticleCountSortedByTag() {
        return statisticsService.showArticleCountSortedByTag();
    }
}
